
/*===================================================================*/
/*=========================页面 常用控制JS ============================*/
/*===================================================================*/
/*=============================页面JS 管理类===========================*/
function PageUtils() {
}
/*标识位*/
HTMLTYPE_SELECT = "SELECT";
HTMLTYPE_CHECKBOX = "CHECKBOX";
HTMLTYPE_INPUT_TEXT = "TEXT";
HTMLTYPE_INPUT_HIDDEN = "HIDDEN";
HTMLTYPE_TEXTAREA = "TEXTAREA";
/*默认的重置方法*/
PageUtils.prototype.defaultReset = function () {
	var paramArray = new Array();
	paramArray[0] = new ResetParam(HTMLTYPE_SELECT, "", "");
	paramArray[1] = new ResetParam(HTMLTYPE_INPUT_TEXT, "", "");
	paramArray[2] = new ResetParam(HTMLTYPE_INPUT_HIDDEN, "", "");
	PageUtils.prototype.reset(paramArray);
};
/**重置方法**/
/*@params:params   必须为ResetParam对象数组           */
PageUtils.prototype.reset = function (params) {
	var falseCode;
	//检查参数是否数组
	if (typeof (params) != "object") {
		alert(typeof (params));
		return false;
	}
	

	//if ((params.constructor + "").match(/function Array()/) == null) {
	//	alert(params.constructor+"");
	//	return false;
	//}
	var _selectU = new SelectUtils();
	var _inputTextU = new InputTextUtils();
	var _inputTextHiddenU = new InputTextHidden();
	for (var i = 0; i < params.length; i++) {
		var item = params[i];
		//检查数组里装的是否ResetParam对象
		if (typeof (item) != "object") {
			falseCode += "," + i + "notype";
			continue;
		}
		//if ((item.constructor + "").match(/function ResetParam/) == null) {
		//	falseCode += "," + i + "noconstrut";
		//	continue;
		//}
		
		//重置处理
		if (HTMLTYPE_SELECT == item.elementtype.toUpperCase) {
			_selectU.reset(item.ids, item.names);
		}
		if (HTMLTYPE_INPUT_TEXT == item.elementtype.toUpperCase) {
			_inputTextU.reset(item.ids, item.names);
		}
		if (HTMLTYPE_INPUT_HIDDEN == item.elementtype.toUpperCase) {
			_inputTextHiddenU.reset(item.ids, item.names);
		}
		if (HTMLTYPE_CHECKBOX == item.elementtype.toUpperCase) {
		}
		if (HTMLTYPE_TEXTAREA == item.elementtype.toUpperCase) {
		}
	}
};
/**/
function ResetParam(elementtype, ids, names) {
	this.elementtype = elementtype;
	this.ids = ids;
	this.names = names;
}
/*================= input HIDDEN 开始==============================*/
function InputTextHiddenUtils() {
}
/*重置方法*/
/*@param  ids  不受影响的InputText的id 格式：,id1,id2,id3,*/
/*@param  names  不受影响的InputText的name 格式：,name1,name2,*/
InputTextHiddenUtils.prototype.reset = function (ids, names) {
	var inputs = document.getElementsByTagName("input");
	for (var i = 0; i < inputs.length; i++) {
		if (inputs[i].type == "hidden") {
			if (ids.indexOf("," + inputs[i].id + ",") != -1) {
				continue;
			}
			if (names.indexOf("," + inputs[i].name + ",") != -1) {
				continue;
			}
			inputs[i].value = "";
		}
	}
};
/*================= input HIDDEN 结束==============================*/
/*================= input text 开始==============================*/
function InputTextUtils() {
}
/*重置方法*/
/*@param  ids  不受影响的InputText的id 格式：,id1,id2,id3,*/
/*@param  names  不受影响的InputText的name 格式：,name1,name2,*/
InputTextUtils.prototype.reset = function (ids, names) {
	var inputs = document.getElementsByTagName("input");
	for (var i = 0; i < inputs.length; i++) {
		if (inputs[i].type == "text") {
			if (ids.indexOf("," + inputs[i].id + ",") != -1) {
				continue;
			}
			if (names.indexOf("," + inputs[i].name + ",") != -1) {
				continue;
			}
			inputs[i].value = "";
		}
	}
};
/*================= input text 结束==============================*/
/*===================select  开始==================================*/
/*SELECT 工具类*/
function SelectUtils() {
}
/*控制select的显示*/
SelectUtils.prototype.displaySelectTag = function () {
	var selectTags = document.getElementsByTagName("select");
	for (var i = 0; i < selectTags.length; i++) {
		selectTags[i].style.display = "";
	}
};
/*控制select不显示*/
SelectUtils.prototype.undisplaySelectTag = function () {
	var selectTags = document.getElementsByTagName("select");
	for (var i = 0; i < selectTags.length; i++) {
		selectTags[i].style.display = "none";
	}
};
/*重置方法*/
/*@param  ids  不受影响的select的id 格式：,id1,id2,id3,*/
/*@param  names  不受影响的select的name 格式：,name1,name2,*/
SelectUtils.prototype.reset = function (ids, names) {
	var selects = document.getElementsByTagName("select");
	for (i = 0; i < selects.length; i++) {
		if (ids.indexOf("," + selects[i].id + ",") != -1) {
			continue;
		}
		if (names.indexOf("," + selects[i].name + ",") != -1) {
			continue;
		}
		if (selects[i].length > 0) {
			for (var j = 0; j < selects[i].length; j++) {
				selects[i].options[j].selected = false;
			}
			selects[i].options[0].selected = true;
		}
	}
};
/*===================select  结束==================================*/
/*================== tr 选中变颜色  开始========================*/
//存储多个列表的上次选中的tr的id
var oldTrStorces = new Array();
/*****参数对象***********/
/*
*@param bgId    本次选中的tr的id
*@param arrayIndex	本列表对应oldTrStorces的数组下标
*@param img_prefix  图片ID前缀   例如img1_2342342,img1为前缀
*@param	initImgId 	页面初始化时图片的Id
*@param	oldClass	最初的class名字
*@param bgClass		变更的class名字
*/
function TRColorParam(bgId, arrayIndex, img_prefix, initImgId, oldClass, bgClass) {
	this.bgId = bgId;
	this.arrayIndex = arrayIndex;
	this.img_prefix = img_prefix;
	this.initImgId = initImgId;
	this.oldClass = oldClass;
	this.bgClass = bgClass;
}
/*tr 变颜色的方法
	*@param tr_id tr的id
	*@param sourceClass 将要被替换的CLASS
	*/
function replaceTRClass(tRColorParam) {
	//选择后的tr class 定义在web.css.iskystyle.css
	var bgClass = "columnInput_selected";
	var oldClass = "columnInput";//选择后的tr class 定义在web.css.iskystyle.css
	var bgId, oldId;//本次选中的tr ID以及上一次选中的tr id
	var bgtr, oldtr;//本次选中的tr对象以及上一次选中的tr对象
	var bgClassName, oldClassName;//本次tr的classname,上一次tr的classname
	var bgImgSrc = "../css/images/tr_selected.bmp";
	var oldImgSrc = "../css/images/tr_unselected.bmp";
	var initImg = document.getElementById(tRColorParam.initImgId);
	if (typeof (initImg) == "object") {
		initImg.src = "../css/images/header_blue.jpg";
	}
	bgId = tRColorParam.bgId;
	if (oldTrStorces[tRColorParam.arrayIndex] != undefined) {
		oldId = oldTrStorces[tRColorParam.arrayIndex];
	} else {
		oldId = "";
	}
	if (bgId == oldId) {//点击相同的列 目前做法不变
		return;
	}
	if (tRColorParam.bgClass == "" || tRColorParam.bgClass == null) {
	} else {
		bgClass = tRColorParam.bgClass;
	}
	if (tRColorParam.oldClass == "" || tRColorParam.oldClass == null) {
	} else {
		oldClass = tRColorParam.oldClass;
	}


	//改变选中的tr
	bgtr = document.getElementById(bgId);
	bgClassName = bgtr.className;
	var msg;
	//改变tr的class
	if (bgClassName.indexOf(oldClass) != -1) {
		bgtr.className = bgClassName.replace(new RegExp(oldClass), bgClass);
	} else {
		bgtr.className = (bgClassName + " " + bgClass).trim();
	}
	//改变图片
	var _tr_prefix = bgId.split("_")[0];
	var _tr_code = bgId.split("_")[1];
	document.getElementById(tRColorParam.img_prefix + "_" + _tr_code).src = bgImgSrc;
	//alert("123")
	
	//还原上次的tr
	if ("" == oldId) {//不存在上一次tr
	} else {
		oldtr = document.getElementById(oldId);
		oldClassName = oldtr.className;
		if (oldClassName.indexOf(bgClass) != -1) {
			oldtr.className = oldClassName.replace(new RegExp(bgClass), oldClass);
		} else {
			oldtr.className = (oldClassName + " " + oldClass).trim();
		}
		//改变图片
		_tr_prefix = oldId.split("_")[0];
		_tr_code = oldId.split("_")[1];
		document.getElementById(tRColorParam.img_prefix + "_" + _tr_code).src = oldImgSrc;
	}
	oldTrStorces[tRColorParam.arrayIndex] = bgId;
}
/*================== tr 选择变颜色  结束========================*/
/*=============checkbox 开始===========================*/
/*checkbox是否给选中
@descipetion:检查指定name的checkbox是否有给选中；
			 假如name为"",就查找所有checkbox,判断是否给选中
@param name；checkbox的名字
@return boolean;true:有checkbox被选中；false:没有
*/
function isselect4checkbox(name) {
	var e;
	if ("" == name) {
		e = document.getElementsByTagName("input");
	} else {
		e = document.getElementsByName(name);
	}
	var isselect = false;
	for (var i = 0; i < e.length; i++) {
		if (e[i].type != "checkbox") {
			continue;
		}
		if (e[i].checked == true) {
			isselect = true;
			break;
		}
	}
	return isselect;
}
/*
checkbox 全选
*/
function selectAll4Checkbox(name) {
	var e;
	if ("" == name) {
		e = document.getElementsByTagName("input");
	} else {
		e = document.getElementsByName(name);
	}
	for (var i = 0; i < e.length; i++) {
		if (e[i].type != "checkbox") {
			continue;
		}
		e[i].checked = true;
	}
}
/*
checkbox 反选
*/
function inverse4Checkbox(name) {
	var e;
	if ("" == name) {
		e = document.getElementsByTagName("input");
	} else {
		e = document.getElementsByName(name);
	}
	for (var i = 0; i < e.length; i++) {
		if (e[i].type != "checkbox") {
			continue;
		}
		e[i].checked = (e[i].checked == true ? false : true);
	}
}
/*
返回选中的checkbox的值，多个checkbox的值以separator的值分开
例如：values="a1,a2,a3"
*/
function values4Checkbox_checked(name, separator) {
	var e;
	var values = "";
	if ("" == name) {
		e = document.getElementsByTagName("input");
	} else {
		e = document.getElementsByName(name);
	}
	for (var i = 0; i < e.length; i++) {
		if (e[i].type.toLowerCase() != "checkbox") {
			continue;
		}
		if (e[i].checked == true) {
			values += e[i].value + separator;
		}
	}
	if ("" != values) {//去掉最后多余的separator
		values = values.substr(0, values.length - separator.length);
	}
	return values;
}
/*checkbox 工具类*/
function CheckboxsUtils() {
}
/*重置方法*/
/*@param  ids  不受影响的select的id 格式：,id1,id2,id3,*/
/*@param  names  不受影响的select的name 格式：,name1,name2,*/
CheckboxsUtils.prototype.reset = function (ids, names) {
	var cs = document.getElementsByTagName("input");
	for (i = 0; i < cs.length; i++) {
		if (cs[i].type.toLowerCase() != "checkbox") {
			continue;
		}
		if (ids.indexOf("," + cs[i].id + ",") != -1) {
			continue;
		}
		if (names.indexOf("," + cs[i].name + ",") != -1) {
			continue;
		}
		cs[i].checked = false;
	}
};
/*=============checkbox 结束===========================*/
/*=============radio 开始=========================*/
/*
返回选中的radio的值，
*/
function values4Radio_checked(name) {
	var e;
	var values = "";
	if ("" == name) {
		e = document.getElementsByTagName("input");
	} else {
		e = document.getElementsByName(name);
	}
	for (var i = 0; i < e.length; i++) {
		if (e[i].type.toLowerCase() != "radio") {
			continue;
		}
		if (e[i].checked == true) {
			values = e[i].value;
			break;
		}
	}
	return values;
}
/*=============radio 结束=========================*/
/*===========判断字符串的长度 开始===================*/
function Len(str) {
	var i, sum;
	sum = 0;
	for (i = 0; i < str.length; i++) {
		if ((str.charCodeAt(i) >= 0) && (str.charCodeAt(i) <= 255)) {
			sum = sum + 1;
		} else {
			sum = sum + 2;
		}
	}
	return sum;
}
/*===========判断字符串的长度 结束===================*/

